package com.springboot2.shiro.data.enity;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.springboot2.shiro.comm.entity.JpaEntity;
import lombok.Getter;
import lombok.Setter;

import javax.persistence.*;

/**
 * User
 *
 * @author Archx[archx@foxmail.com]
 * at 2018/7/13 21:12
 */
@Entity
@Getter
@Setter
@Table(name = "tb_users")
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class User extends JpaEntity<Integer> {

    @Column(name = "username", length = 64)
    private String username;

    @Column(name = "password", length = 64)
    private String password;

    @Column(name = "role_id")
    private Integer roleId;

    @Enumerated(EnumType.STRING)
    @Column(name = "state", length = 20)
    private State state;

    // 关联关系，不产生外键
    @ManyToOne
    @JoinColumn(name = "role_id", insertable = false, updatable = false,
            foreignKey = @ForeignKey(value = ConstraintMode.NO_CONSTRAINT, name = "none"))
    private Role role;

    public enum State {
        Enabled, Disabled, Deleted
    }
}
